package com.cdh.springboot.controller;


import com.cdh.springboot.entity.User;
import com.cdh.springboot.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author CDHong
 * @since 2021-05-24
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IUserService userService;

    @GetMapping("/getUser/{id}")
    public User selectUser(@PathVariable("id") Integer id){
        User user = userService.getById(id);
        return user;
    }

    @PostMapping("/addUser")
    public String selectUser(User user){
        boolean result = userService.save(user);
        if(result){
            return "success";
        }
        else{
            return "fail";
        }

    }
}
